package star.基础.队列最大值;

import java.util.LinkedList;

class MaxQueue {
    LinkedList<Integer> list;
    LinkedList<Integer> queue;
    public static void main(String[] args) {
        MaxQueue maxQueue = new MaxQueue();
        maxQueue.push_back(1);
        maxQueue.push_back(2);
        System.out.println(maxQueue.pop_front());
    }


    public MaxQueue() {
        list = new LinkedList<>();
        queue = new LinkedList<>();
    }

    public int max_value() {
        if (!queue.isEmpty()){
            return queue.peekLast();
        }else {
            return -1;
        }
    }

    public void push_back(int value) {
        list.add(value);
        if (!queue.isEmpty() && queue.peekLast()>value){
            return;
        }
        queue.add(value);
    }

    public int pop_front() {
        if (list.isEmpty()) return -1;
        if (list.peekLast().equals(queue.peekLast())) queue.pop();
        return list.pop();
    }
}

